package com.nekonomics
package types

import doobie.util.meta.Meta
import zio.json.JsonEncoder

enum OrderStatus {
  case Pending
  case Paid // 已支付待发货
  case Shipped // 已发货
  case Delivered // 已送达
  case Completed // 已完成
  case Cancelled // 已取消

  override def toString: String = productPrefix.toLowerCase
}

object OrderStatus {

  def fromStr(str: String) = str match {
    case "pending" => Right(Pending)
    case "paid" => Right(Paid)
    case "shipped" => Right(Shipped)
    case "delivered" => Right(Delivered)
    case "completed" => Right(Completed)
    case "cancelled" => Right(Cancelled)
    case other => Left(s"Invalid OrderStatus: $other")
  }

  given JsonEncoder[OrderStatus] = JsonEncoder[String].contramap(_.toString)
  given Meta[OrderStatus] =
    Meta[String].tiemap(fromStr)(_.toString)
}